﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MudEngine.Parsing.AST
{
    public class FunctionDeclaration : NamedAstNode
    {
		public Modifiers Modifiers { get; private set; }
		public int LocalDataSize { get; set; }

		private BlockStatement _body;
        public BlockStatement Body
		{
			get
			{
				return _body;
			}
			set
			{
				this._body = value;
				value.Parent = this;
			}
		}
        public List<ParameterDeclaration> Parameters { get; private set; }
        public int NextAddress { get; set; }

        public FunctionDeclaration(Modifiers m, AType type, string name) : base(name)
        {
			this.Modifiers = m;
            this.Type = type;
            this.Parameters = new List<ParameterDeclaration>();
        }

        public override void AcceptVisitor<C>(IAstNodeVisitor<C> visitor, C ctx)
        {
            visitor.VisitFunctionDeclaration(this, ctx);
        }

        internal void AddParameterDeclaration(ParameterDeclaration pd)
        {
            this.Parameters.Add(pd);
        }

        public bool HasParameters(List<ParameterDeclaration> parameters)
        {
            if (parameters.Count == this.Parameters.Count)
            {
                for (int idx = 0; idx < parameters.Count; idx++)
                {
                    if (this.Parameters[idx].Type != parameters[idx].Type)
                        return false;
                }
            }
            return true;
        }
    }
}
